home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / util / rexx / xdmd1.lha / FindReq.xdme < prev    next >
Text File  |  1994-10-23  |  3KB  |  139 lines

  1. /* FindReq.xdme © 1992 Fergus Duniho */
  2. /* Requester for Find, Find & Replace, Set Find and Replace Strings */
  3.  
  4. if ~show("L","rexxarplib.library") then
  5.     if ~addlib("rexxarplib.library",0,-30,0) then exit
  6.  
  7. F = GetEnv('F')
  8. R = GetEnv('R')
  9. options results
  10. address 'XDME.1'
  11. 'rxresult $igncase'
  12. igncase = result
  13. N = -1
  14. 'blocktype character'
  15.  
  16. Address AREXX '"Call CreateHost CPORT, NOTPORT"'
  17. Do Until ShowList(P,CPORT)
  18.     Call Delay(10)
  19. End
  20.  
  21. IDCMP = 'GADGETUP+CLOSEWINDOW'
  22. FLAGS = 'ACTIVATE+BACKFILL+WINDOWDRAG+WINDOWCLOSE+WINDOWDEPTH'
  23. TTEXT = 'XDMD Find & Replace Requester © 1993 Fergus Duniho'
  24.  
  25. Call OpenWindow CPORT, 50, 25, 500, 90, IDCMP, FLAGS, TTEXT
  26.  
  27. Call SetDrMd CPORT, COMPLEMENT
  28. Call Move CPORT, 20, 22
  29. Call Text CPORT, 'Find String    : '
  30. Call AddGadget CPORT, 155, 14, 'F', F, 'F = "(" || strip("%g") || ")"; Call ActivateGadget CPORT, "R"', 300
  31.  
  32. Call Move CPORT, 20, 42
  33. Call Text CPORT, 'Replace String : '
  34. Call AddGadget CPORT, 155, 34, 'R', R, 'R = "(" || strip("%g") || ")"; Call ActivateGadget CPORT, "N"', 300
  35.  
  36. Call Move CPORT, 20, 62
  37. Call Text CPORT, 'Replacements   : '
  38. Call AddGadget CPORT, 155, 54, 'N', N, 'N = "%g"', 50
  39.  
  40. Call Move CPORT, 230, 62
  41. Call Text CPORT, 'Ignore Case : '
  42. Call AddGadget CPORT, 350, 54, 'ign', ' On ', 'igncase = 1; Call ICase'
  43. Call AddGadget CPORT, 400, 54, 'sen', ' Off ', 'igncase = 0; Call ICase'
  44. Call AddGadget CPORT, 15, 74, 'find', ' Find ', 'find F; Call Hlight'
  45. Call AddGadget CPORT, 80, 74, 'prev', ' Prev ', 'findstr F; prev; Call Hlight'
  46. Call AddGadget CPORT, 145, 74, 'repfind', ' Replace & Find ', 'Call Repfind'
  47. Call AddGadget CPORT, 290, 74, 'replace', ' Replace N Times ', 'Call ReplaceN'
  48. Call AddGadget CPORT, 440, 74, 'set', ' Set ', 'Call Set; Exit'
  49. Call ModifyHost CPORT, CLOSEWINDOW, 'Call Quit CPORT; Exit'
  50.  
  51. Call ICase
  52. Call ActivateGadget CPORT, 'F'
  53.  
  54. Call OpenPort MAINPORT
  55. Do Until ShowList(P, MAINPORT)
  56.     Call Delay(10)
  57. End
  58.  
  59. Call SetNotify(CPORT, GADGETUP, MAINPORT)
  60. Call SetNotify(CPORT, CLOSEWINDOW, MAINPORT)
  61.  
  62. Do Forever
  63.     Call WaitPkt(MAINPORT)
  64.     PACKET = GetPkt(MAINPORT)
  65.     If PACKET ~== Null() Then Interpret GetArg(packet, 0)
  66. End
  67. Exit
  68.  
  69. ICase:
  70.     if igncase = 1 then do
  71.         Call SetGadget CPORT, 'ign', on
  72.         Call SetGadget CPORT, 'sen', off
  73.         ignorecase on
  74.     end
  75.     else do
  76.         Call SetGadget CPORT, 'ign', off
  77.         Call SetGadget CPORT, 'sen', on
  78.         ignorecase off
  79.     end
  80.     'set igncase' igncase
  81. Return
  82.  
  83. Set:
  84.     Call Quit CPORT
  85.     CASE = Compress(CASE)
  86.     ignorecase CASE
  87.     if F = "()" | F = "" then do
  88.         'unsetenv F'
  89.     end
  90.     else do
  91.         'setenv F' F
  92.     end
  93.     if R = "()" | R = "" then do
  94.         'unsetenv R'
  95.     end
  96.     else do
  97.         'setenv R' R
  98.     end
  99.     'set Case' CASE
  100. Return
  101.  
  102. Hlight:
  103.     L = length(F) - 3
  104.     ping 9
  105.     unblock
  106.     block
  107.     C = "col +" || L
  108.     C
  109.     block
  110.     C = "col -" || L
  111.     C
  112. Return
  113.  
  114. Repfind:
  115.     findstr F
  116.     repstr R
  117.     'scanf %s'
  118.     'rxresult $scanf'
  119.     Q = '(' || result || ')'
  120.     if abbrev(Q, F) > 0 then do
  121.         'replace'
  122.     end
  123.     next
  124.     Call Hlight
  125. Return
  126.  
  127. ReplaceN:
  128.     findstr F
  129.     repstr R
  130.     'scanf %s'
  131.     'rxresult $scanf'
  132.     Q = '(' || result || ')'
  133.     if abbrev(Q, F) > 0 then do
  134.         'replace'
  135.     end
  136.     C = "repeat" N "nextr"
  137.     C
  138. Return
  139.